(function (vc, vm) {

    vc.extends({
        data: {
            addHousekeepingServPoolUserInfo: {
                poolId: '',
                shopId: '',
                staffId: '',
                staffName: '',
                preStaffId: '',
                preStaffName: '',
                startTime: '',
                endTime: '',
                poolEvent: '',
                preRuId: '',
                state: '',
                context: '',
                housekeepingServUserDtos: []
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addHousekeepingServPoolUser', 'openAddHousekeepingServPoolUserModal', function (_params) {
                $that.refreshAddHousekeepingServPoolUserInfo();
                $('#addHousekeepingServPoolUserModel').modal('show');
                $that.addHousekeepingServPoolUserInfo.poolId=_params._housekeepingServPool.poolId;
                $that.addHousekeepingServPoolUserInfo.shopId=_params._housekeepingServPool.shopId;
                $that.addHousekeepingServPoolUserInfo.housekeepingServUserDtos = _params._housekeepingServPool.housekeepingServDtos[0].housekeepingServUserDtos;
 
            });
        },
        methods: {
            addHousekeepingServPoolUserValidate: function () {
                return vc.validate.validate({
                    addHousekeepingServPoolUserInfo: $that.addHousekeepingServPoolUserInfo
                }, {
                    'addHousekeepingServPoolUserInfo.staffId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "员工ID不能为空"
                        }
                    ],
                        'addHousekeepingServPoolUserInfo.context': [
                            {
                                limit: "required",
                                param: "",
                                errInfo: "处理说明不能为空"
                            }
                        ]

                        });
            },
            saveHousekeepingServPoolUserinfo: function () {
                if (!$that.addHousekeepingServPoolUserValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/housekeepingServPoolUser/saveServPoolUser',
                    JSON.stringify($that.addHousekeepingServPoolUserInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addHousekeepingServPoolUserModel').modal('hide');
                            vc.emit('housekeepingServPoolManage', 'listHousekeepingServPool', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            setAddStaffName:function(_staffId){
                $that.addHousekeepingServPoolUserInfo.housekeepingServUserDtos.forEach(item => {
                    if (item.staffId == _staffId) {
                        $that.addHousekeepingServPoolUserInfo.staffName = item.staffName;
                    }
                });
            },
            refreshAddHousekeepingServPoolUserInfo: function () {
                $that.addHousekeepingServPoolUserInfo = {
                    poolId: '',
                    shopId: '',
                    staffId: '',
                    staffName: '',
                    preStaffId: '',
                    preStaffName: '',
                    startTime: '',
                    endTime: '',
                    poolEvent: '',
                    preRuId: '',
                    state: '',
                    context: '',
                    housekeepingServUserDtos: []
                }
            }
        }
    });

})(window.vc, window.$that);
